import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:thingskit/components/selectBox.dart';

import '../../../utils/const.dart';

class GroupCollapseController extends GetxController {
  final firstGroup = TextEditingController(); //第一组别
  final secondGroup = TextEditingController(); // 第二组别
  final isSecondGroup = false.obs;// 是否开启第二组别

  void setDefault() {
    firstGroup.text = '0';
    secondGroup.text = '0';
    isSecondGroup.value = false;
  }

  void setModeFromJson(Map<String, dynamic> json) {
    firstGroup.text = json['new_group'].toString();
    secondGroup.text = json['second_group_id'].toString();
    isSecondGroup.value = json['is_second_group'];
  }
}

class GroupCollapse extends StatelessWidget {
  GroupCollapse({super.key});

  final GroupCollapseController controller = Get.put(GroupCollapseController());

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      return Container(
        padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
        child: Column(
          children: [
            Row(
              children: [
                SizedBox(
                  width: 40,
                  child: Text('第一组号', style: TextStyle(fontSize: 18)),
                ),
                SizedBox(width: 10),
                SelectBox(
                  initialValue: controller.firstGroup.text,
                  options: groupOptions,
                  onChanged: (value) {
                    controller.firstGroup.text = value;
                  },
                  label: '',
                ),
              ],
            ),
            const SizedBox(height: 10),
            Row(
              children: [
                Switch(
                  activeColor: Colors.blue,
                  value: controller.isSecondGroup.value,
                  onChanged: (value) => controller.isSecondGroup.value = value,
                ),
                SizedBox(
                  width: 40,
                  child: Text('第二组号', style: TextStyle(fontSize: 18)),
                ),
                SelectBox(
                  initialValue: controller.secondGroup.text,
                  options: groupOptions,
                  onChanged: (value) {
                    controller.secondGroup.text = value;
                  },
                  label: '',
                ),
              ],
            ),
          ],
        ),
      );
    });
  }
}
